﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using CNVP.Framework.Helper;
using System.Data;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    public class CNVP_RetrievePwdInfo
    {

       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_RetrievePwdInfo obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "RetrievePwdInfo (ID, PostTime, UserName)");
            sql.Append("values( @ID, @PostTime, @UserName)");

            SqlParameter[] pra = {
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@PostTime",obj.PostTime),
                            new SqlParameter("@UserName",obj.UserName)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }
        /// <summary>
        /// 删除已经存在的记录
        /// </summary>
        /// <param name="id">GUID值</param>
        /// <returns>受影响的信息条数</returns>
        public int DeleteObject(Guid id)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from  [" + Prefix + "RetrievePwdInfo] where  [ID]=@ID");

            SqlParameter[] pra = {
                            new SqlParameter("@ID",id)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        public Model.CNVP_RetrievePwdInfo LoadById(Guid ID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select PostTime, UserName from " + Prefix + "RetrievePwdInfo");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            Model.CNVP_RetrievePwdInfo cnvp_retrieverwdinfo = new Model.CNVP_RetrievePwdInfo();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_retrieverwdinfo.PostTime = dr["PostTime"] is DBNull ? DateTime.Now : (DateTime)dr["PostTime"];
                cnvp_retrieverwdinfo.UserName = dr["UserName"] is DBNull ? String.Empty : (string)dr["UserName"];
            }
            return cnvp_retrieverwdinfo;
        }


        #endregion
    }
}
